package com.zxn.kotlin.str

//拼接特定属性

fun main(){
    joinToName()
    joinToEmail()

}

data class User(val id: Int, val name: String, val email: String)

val users = listOf(
    User(1, "Alice", "alice@example.com"),
    User(2, "Bob", "bob@example.com"),
    User(3, "Charlie", "charlie@example.com")
)

fun joinToName(){
    // 只拼接名字
    val names = users.joinToString(", ") { it.name }
    println(names)
    // 输出: Alice, Bob, Charlie
}

fun joinToEmail(){
    // 只拼接邮箱
    val emails = users.joinToString(", ") { it.email }
    println(emails) // 输出: alice@example.com, bob@example.com, charlie@example.com
}




